/**
 * Created by DevilsEyes on 2016/4/9.
 */
define(['text!path/info/tmp.html', 'layer'], function (page, layer) {
    'use strict';

    var render = template.compile(page);
    var symbol = {};

    //获取请求
    var Query = function (queryStr) {
        var that = this;
        queryStr = queryStr || '';
        queryStr.replace(/([^=&]*)(?:=)?([^=&]*)?/g, function (str, key, value, index) {
            if (str != '') {
                that[key] = value;
            }
            return str;
        });
    };

    var vm = new Page.creat({
        $id: 'info',
        $model: {
            data: {},
            $: {},
            redirect: '',
            type: '',
            _id: null,
            init: function (query) {

                query = new Query(query);
                vm.data.redirect = query.redirect || '';
                $('#page').html(render({
                    type: vm.type,
                    message: query.message || '',
                    tips: query.tips || '',
                    button: query.button || '',
                    redirect: query.redirect || ''
                }));

                ex.async(function () {

                    vm.bindEvent(vm.event);
                    vm.bind$(vm.$);

                    vm.$.header.css('top', db.h * 0.2);
                    vm.$.footer.css('top', db.h * 0.6);
                });

            },
            event: {
                redirect: function () {
                    console.log(vm.data.redirect);
                    page_back_and_go('#' + vm.data.redirect);
                }
            }
        }
    });

    return {
        error: function (params) {
            vm.$init({
                setTitle: '出错了!'
            });
            vm.type = 'error';
            vm.init(params.query);
        },
        success: function (params) {
            vm.$init({
                setTitle: '支付成功!'
            });
            vm.type = 'success';
            vm.init(params.query);
        }
    }
});